<template>
    <el-container>
        <!-- <el-header >Header</el-header> -->
        <el-container>
            <el-aside width="200px">
              <h3 style="padding-left:20px;padding-top:20px;">喵哆旺电商</h3>
              <el-menu
                default-active="2"
                active-text-color="#ffd04b"
                router
                unique-opened
                :default-active="defaultPage"
                >
                <!-- <el-menu-item index="broadCast">轮播图管理</el-menu-item> -->
                <el-menu-item index="commodity">商品管理</el-menu-item>
                <el-menu-item index="activity">活动管理</el-menu-item>
                <el-menu-item index="order">订单管理</el-menu-item>
                <el-menu-item index="carriage">运费管理</el-menu-item>
              </el-menu>
            </el-aside>
            <el-main>
              <router-view></router-view>
            </el-main>
        </el-container>
    </el-container>
</template>
<style>
  .el-header{
    background-color: #B3C0D1;
  }
  .el-container{
    /* height: 100%; */
  }
  .el-aside{
    /* height: 100%; */
  }
</style>
<script>
import {imgInfo} from '../../tool/user'
import { setCookie } from '../../tool/cookie'
export default {
  data(){
    return{
      flag:true,
      defaultPage:'commodity',
      socket:null
    }
  },
  mounted(){
    let that = this
    let url = window.location.href
    let routerArr = url.split('/')
    this.defaultPage = routerArr[routerArr.length - 1]
    let WSurl = 'ws://192.168.3.188:8086/shop_backend/order/'
    that.socket = new WebSocket(WSurl);
    that.socket.addEventListener('open', function (event) {
        // this.socket.send(JSON.stringify('Hello Server!'));
    })
    that.socket.addEventListener('message', function (event) {
        let data = JSON.parse(event.data)
        // console.log(data)
        if(data.content.goods){
          that.$store.commit('changeNotice',data.content)
        }
    });
    // var date=new Date();
    // console.log('现在的时间是',date.toGMTString())
    // var expiresHours=8;
    // date.setTime(date.getTime()+expiresHours*3600*1000);
    // console.log('过期的时间是',date.toGMTString())
  },
  watch:{
    $route(newVal,oldVal){
      this.defaultPage = newVal.name 
    }
  },
  beforeDestroy(){
    this.socket.close()
  }
}
</script>
